﻿using System;
using Infrastructure;

namespace Domain
{
    public interface IBorrower : IRole<UniqueId>
    {
        void BorrowBook(Book book);
        void ReturnBook(Book book);
    }

    public class Borrower : Role<LibraryAccount, UniqueId>, IBorrower
    {
        private ILibraryService library = DependencyResolver.Resolve<ILibraryService>();

        public Borrower(LibraryAccount account)
            : base(account)
        {
            if (account.IsLocked)
            {
                throw new NotSupportedException("Locked account is not allowed to act as borrower.");
            }
        }

        public void BorrowBook(Book book)
        {
            //通知图书馆把书借给我
            library.LendBook(book, this);
        }
        public void ReturnBook(Book book)
        {
            //通知图书馆接收我要归还的书
            library.ReceiveReturnedBook(book, this);
        }
    }
}
